--
-- Author:      name
-- DateTime:    2018-04-23 17:19:33
-- Description: 服务管理


require "skynet.manager"
local skynet = require "skynet"
local NodeMessage = import("NodeMessage")
local MessageDispatch = import("MessageDispatch")
local ClusterManager = import("ClusterManager")
local MessageHandler = import("manager.MessageHandler")
local ServerInfo = import("ServerInfo")


--除了global禁止出现别的全局变量

local function init()

	local message_dispatch = MessageDispatch.new()	
	local node_message = NodeMessage.new()
	local message_handler = MessageHandler.new(message_dispatch, node_message)
	local server_info = ServerInfo.new()
	local cluster_manager = ClusterManager.new(message_dispatch)

	global.message_dispatch = message_dispatch
	global.node_message = node_message
	global.message_handler = message_handler
	global.server_info = server_info
	global.cluster_manager = cluster_manager


	skynet.dispatch("lua", message_dispatch:dispatch())
	--开启集群节点
	cluster_manager:open(server_info)
end


---------------------------------------------------------
-- skynet
---------------------------------------------------------

skynet.start(function()

	skynet.register('.manager')

	init()

end)